<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #box {
            width: 300px;
            height: 300px;
            background: pink;
            transition: all 1s;
        }
        .hide{
            opacity: 0;
        }
        .show {
            opacity: 1;
        }
    </style>
</head>
<body>
    <div>
        <button onclick="toggleBox()">切换显示</button>
    </div>
    <div id="box" class="show"></div>

    <script>
        function toggleBox() {
            const dom = document.querySelector('#box')
            if (dom.className=="show") {
                dom.className = 'hide'
            }else {
                dom.className = 'show'
            }
        }
    </script>
</body>
</html>